package com.yoyo.itravel.service.impl;

import com.yoyo.itravel.bean.SightCompany;
import com.yoyo.itravel.constants.MsgConstant;
import com.yoyo.itravel.dao.ISightCompanyDao;
import com.yoyo.itravel.exceptions.SightCompanyException;
import com.yoyo.itravel.exceptions.TicketTypeDetailException;
import com.yoyo.itravel.service.ISightCompanyService;
import com.yoyo.itravel.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

/**
 * @Description 景点公司相关操作服务层接口实现类
 * 
 * @Author HZX
 * @Date 2020/6/19 10:37
 * @Version 1.0
 */
@Service
public class SightCompanyServiceImpl implements ISightCompanyService {

    @Autowired
    private ISightCompanyDao sightCompanyDao;

    /**
     * @Description 添加景点公司
     *
     * @Param sightCompany
     * @Return boolean
     */
    @Override
    public boolean addSightCompany(SightCompany sightCompany) throws SightCompanyException {
        if (sightCompany == null) {
            throw new SightCompanyException("SightCompany对象为null！");
        }
        try {
            return sightCompanyDao.updateById(sightCompany) == 1;
        } catch (SQLException e) {
            e.printStackTrace();
            throw new SightCompanyException("添加景点公司失败！");
        }
    }

    /**
     * @Description 通过景点公司id删除景点公司
     *
     * @Param sightCompany
     * @Return boolean
     */
    @Override
    public boolean deleteById(SightCompany sightCompany) throws SightCompanyException {
        if (sightCompany == null) {
            throw new SightCompanyException("SightCompany对象为null！");
        }
        try {
            return sightCompanyDao.updateById(sightCompany) == 1;
        } catch (SQLException e) {
            e.printStackTrace();
            throw new SightCompanyException("通过景点公司id删除景点公司失败！");
        }
    }

    /**
     * @Description 通过景点公司属性查询景点公司
     *
     * @Param sightCompany
     * @Return com.yoyo.itravel.bean.SightCompany
     */
    @Override
    public List<SightCompany> find(SightCompany sightCompany) throws SightCompanyException {
        if (sightCompany == null) {
            throw new SightCompanyException("SightCompany对象为null！");
        }
        try {
            return sightCompanyDao.select(sightCompany);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new SightCompanyException("通过景点公司属性查询景点公司失败！");
        }
    }

    /**
     * @Description 通过景点公司id修改景点公司信息
     *
     * @Param sightCompany
     * @Return boolean
     */
    @Override
    public boolean updateById(SightCompany sightCompany) throws SightCompanyException {
        if (sightCompany == null) {
            throw new SightCompanyException("SightCompany对象为null！");
        }
        try {
            return sightCompanyDao.updateById(sightCompany) == 1;
        } catch (SQLException e) {
            e.printStackTrace();
            throw new SightCompanyException("通过景点公司id修改景点公司信息失败！");
        }
    }

    /**
     * @Description 通过门票具体类型id查找商家支付宝UID
     *
     * @Param detailTypeId
     * @Return java.lang.String
     */
    @Override
    public String findAlipayUIDByDetailTypeId(String detailTypeId) throws SightCompanyException {
        if (StringUtils.isEmpty(detailTypeId)) {
            throw new SightCompanyException("门票具体类型id为空！");
        }
        try {
            return sightCompanyDao.selectAlipayUIDByDetailTypeId(detailTypeId);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new SightCompanyException("通过门票具体类型id查找商家支付宝UID失败！");
        }
    }
}
